{extend name="../application/index/view/index/base.html" /}

{block name="main-content"}
<!-- 导航栏开始 -->
<div class="breadcrumbs" id="breadcrumbs">
    <script type="text/javascript">
        try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
    </script>

    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="#">权限控制</a>
        </li>
        <li class="active">管理员列表</li>
    </ul><!-- .breadcrumb -->

    <div class="nav-search" id="nav-search">
        <form class="form-search">
									<span class="input-icon">
										<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
										<i class="icon-search nav-search-icon"></i>
									</span>
        </form>
    </div><!-- #nav-search -->
</div>
<!-- 导航栏结束 -->
<div style="margin: 15px;">
    <button class="btn btn-success" style="margin-bottom: 15px;" onclick="add()">
        <i class="icon-edit"></i>
        添加管理员
    </button>

    <table class="table table-striped table-bordered table-hover table-condensed">
        <tr>
            <th width="10%">用户名</th>
            <th>用户组</th>
            <th>操作</th>
        </tr>
        {volist name="data" id="v"}
            <tr>
                <td>{$v['username']}</td>
                <td>{$v['title']}</td>
                <td>
                    <a href="javascript:void(0);" onclick="edit(this)" group_ids="{$v['group_id']}" status="{$v['status']}" password="{$v['password']}" email="{$v['email']}" phone="{$v['phone']}" id="{$v['id']}" username="{$v['username']}">修改权限或密码</a>
                </td>
            </tr>
        {/volist}
    </table>
</div>

<!-- 添加菜单模态框开始 -->
<div class="modal fade" id="user-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title">
                    添加用户
                </h4>
            </div>
            <div class="modal-body">
                <form class="form-inline" method="post" action="/index.php/index/auth/add_admin">
                    <table class="table table-striped table-bordered table-hover table-condensed">
                        <tr>
                            <th>管理组</th>
                            <td>
                                {volist name="group" id="v"}
                                    {$v['title']}
                                    <input class="xb-icheck" type="checkbox" name="group_ids[]" value="{$v['id']}">
                                    &emsp;
                                {/volist}
                            </td>
                        </tr>
                        <tr>
                            <th>姓名</th>
                            <td>
                                <input class="form-control" type="text" name="username">
                            </td>
                        </tr>
                        <tr>
                            <th>手机号</th>
                            <td>
                                <input class="form-control" type="text" name="phone">
                            </td>
                        </tr>
                        <tr>
                            <th>邮箱</th>
                            <td>
                                <input class="form-control" type="text" name="email">
                            </td>
                        </tr>
                        <tr>
                            <th>初始密码</th>
                            <td>
                                <input class="form-control" type="text" name="password">
                            </td>
                        </tr>
                        <tr>
                            <th>状态</th>
                            <td>
                                <span class="inputword">允许登录</span>
                                <input class="xb-icheck" type="radio" name="status" value="1" checked="checked">
                                &emsp;
                                <span class="inputword">禁止登录</span>
                                <input class="xb-icheck" type="radio" name="status" value="0">
                            </td>
                        </tr>
                        <tr>
                            <th></th>
                            <td>
                                <input class="btn btn-success" type="submit" value="添加">
                                <input class="btn btn-success" type="reset" value="重置">
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 添加菜单模态框结束 -->

<!-- 修改菜单模态框开始 -->
<div class="modal fade" id="user-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title">
                    修改用户
                </h4>
            </div>
            <div class="modal-body">
                <form class="form-inline" method="post" action="/index.php/index/auth/edit_admin">
                    <table class="table table-striped table-bordered table-hover table-condensed">
                        <tr>
                            <th>用户ID</th>
                            <td>
                                <input class="form-control" type="text" name="id" readonly="readonly">
                            </td>
                        </tr>
                        <tr>
                            <th>管理组</th>
                            <td>
                                {volist name="group" id="v"}
                                {$v['title']}
                                <input class="xb-icheck" type="checkbox" name="group_ids[]" value="{$v['id']}">
                                &emsp;
                                {/volist}
                            </td>
                        </tr>
                        <tr>
                            <th>姓名</th>
                            <td>
                                <input class="form-control" type="text" name="username">
                            </td>
                        </tr>
                        <tr>
                            <th>手机号</th>
                            <td>
                                <input class="form-control" type="text" name="phone">
                            </td>
                        </tr>
                        <tr>
                            <th>邮箱</th>
                            <td>
                                <input class="form-control" type="text" name="email">
                            </td>
                        </tr>
                        <tr>
                            <th>初始密码</th>
                            <td>
                                <input class="form-control" type="text" name="password">
                            </td>
                        </tr>
                        <tr>
                            <th>状态</th>
                            <td>
                                <span class="inputword">允许登录</span>
                                <input class="xb-icheck" type="radio" name="status" value="1" checked="checked">
                                &emsp;
                                <span class="inputword">禁止登录</span>
                                <input class="xb-icheck" type="radio" name="status" value="0">
                            </td>
                        </tr>
                        <tr>
                            <th></th>
                            <td>
                                <input class="btn btn-success" type="submit" value="修改">
                                <input id="resetBtn" class="btn btn-success" type="reset" value="重置" style="display: none;">
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 修改菜单模态框结束 -->
<script>

    // 添加菜单
    function add(){
        $("input[name='title']").val('');
        $('#user-add').modal('show');
    }

    function edit(ele){
        $('#resetBtn').trigger("click");
        var group_ids = $(ele).attr('group_ids');
        group_ids = group_ids.split(',');
        $('#user-edit').find('.xb-icheck').removeAttr("checked");

        group_ids.forEach(function (id) {
            $('#user-edit').find('[value='+id+']:checkbox').prop('checked',true);
        });
        if($(ele).attr('status') == 1){
            $('#user-edit').find('[value=1]:radio').prop('checked',true);
        }else{
            $('#user-edit').find('[value=0]:radio').prop('checked',true);
        }
        $('#user-edit').find('input[name=id]').val($(ele).attr('id') || "");
        $('#user-edit').find('input[name=username]').val($(ele).attr('username')|| "");
        $('#user-edit').find('input[name=phone]').val($(ele).attr('phone')|| "");
        $('#user-edit').find('input[name=email]').val($(ele).attr('email')|| "");
        $('#user-edit').find('input[name=password]').val($(ele).attr('password')|| "");
        $('#user-edit').modal('show');
    }

</script>
{/block}
